<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta name="author" content="">
    <title></title>  <link rel="icon" href="/template/pc1/images/wmh_favicon.ico" type="image/x-icon" />
    <% include("../inc/input_css.html"){}%>

    <!--<link type="text/css" rel="stylesheet" href="http://sc.35wang.cn/admin/css/style.css" media="all" />-->

    <style>
        label{
            width: 140px!important;
        }
    </style>

    <%
    var isAdd = false;
    var isEdit = false;
    if(isEmpty(deliveryType.id)){
    isAdd = true;
    }else{
    isEdit = true;
    }%>
</head>
<body>
<div class="ibox">
    <div class="ibox-title">
        <div class="pull-left mbx navbar_title">
            <span class="current">商城设置</span>
            <span class="line">/</span>
            <span class="current"><a href="list">配送方式</a></span><span class="line">/</span>
            <%if(isAdd){%>添加配送方式<%}else{%>编辑配送方式<%}%>
        </div>
    </div>
    <div class="ibox-content">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="padding-40">
                    <form class="form-horizontal form-validate" method="post" id="form" action="<%if (isAdd){%>save<%}else{%>update<%}%>" name="theForm">
                        <input type="hidden" name="deliveryType.id" value="${deliveryType.id!}" />
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><span class="maroon">*</span>配送方式名称</label>
                                <div class="col-sm-3">
                                    <input type="text" name="deliveryType.name" id="deliveryTypeName" value="${deliveryType.name!}" class="form-control light-input" required>
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><span class="maroon">*</span>配送类型</label>
                                <div class="col-sm-3">
                                    <select name="deliveryMethod" id="deliveryMethod" onchange="changeDelivery()" value="" class="form-control light-input" required>
                                        <option value="">请选择...</option>
                                        <%for(list in allDeliveryMethod){%>
                                            <option value="${list}"<%if (list == deliveryType.deliveryMethodValue!){%> selected <%}%>>
                                                ${i18n("DeliveryMethod." + list)}
                                            </option>
                                        <%}%>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group" id="defaultDeliveryCorp">
                                <label class="col-sm-2 control-label">默认物流公司</label>
                                <div class="col-sm-3">
                                    <select name="deliveryType.defaultDeliveryCorp_id" class="form-control light-input">
                                        <option value="">请选择...</option>
                                        <%for(list in allDeliveryCorp){%>
                                        <option value="${list.id}" <%if (list.id == deliveryType.defaultDeliveryCorp_id!){%>selected <%}%>>
                                        ${list.name}
                                        </option>
                                        <%}%>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group" id="firstWeight">
                                <label class="col-sm-2 control-label"><span class="maroon">*</span>首重量</label>
                                <div class="row">
                                    <div class="col-sm-2">
                                        <input type="text" name="deliveryType.firstWeight"  value="${deliveryType.firstWeight!0}" class="form-control light-input" required>
                                    </div>
                                    <div class="col-sm-1" >
                                        <select name="firstWeightUnit" class="form-control light-input">
                                            <%for(list in allWeightUnit){%>
                                            <option value="${list}"<%if (list == deliveryType.firstWeightUnitValue!){%> selected <%}%>>
                                            ${i18n("WeightUnit." + list)}
                                            </option>
                                            <%}%>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group" id="continueWeight">
                                <label class="col-sm-2 control-label"><span class="maroon">*</span>续重量</label>
                                <div class="row">
                                    <div class="col-sm-2">
                                        <input type="text" name="deliveryType.continueWeight"  value="${deliveryType.continueWeight!0}" class="form-control light-input" required="true">
                                    </div>
                                    <div class="col-sm-1" >
                                        <select name="continueWeightUnit" class="form-control light-input">
                                            <%for(list in allWeightUnit){%>
                                            <option value="${list}"<%if (list == deliveryType.continueWeightUnitValue!){%> selected <%}%>>
                                            ${i18n("WeightUnit." + list)}
                                            </option>
                                            <%}%>
                                        </select>
                                    </div>
                                </div>

                            </div>
                            <div class="form-group" id="firstWeightPrice">
                                <label class="col-sm-2 control-label"><span class="maroon">*</span>首重价格</label>
                                <div class="col-sm-3">
                                    <input type="text" name="deliveryType.firstWeightPrice"  value="${deliveryType.firstWeightPrice!0}" class="form-control light-input" required=>
                                </div>

                            </div>
                            <div class="form-group" id="continueWeightPrice">
                                <label class="col-sm-2 control-label"><span class="maroon">*</span>续重价格</label>
                                <div class="col-sm-3">
                                    <input type="text" name="deliveryType.continueWeightPrice"  value="${deliveryType.continueWeightPrice!0}" class="form-control light-input" required="true">
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><span class="maroon">*</span>排序</label>
                                <div class="col-sm-3">
                                    <input type="text" name="deliveryType.orderList"  value="${deliveryType.orderList!50}" class="form-control light-input" required="true">
                                </div>

                            </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span class="maroon" >*</span >所辖地区</label>

                            <td align="left">
                                <fieldset style="">
                                    <table style="width: 700px;" align="left">
                                        <tr>
                                            <td id="regionCell">
                                                <%for(list in recordList!){%>
                                                    <input type="checkbox" name="regions[]" value="${list.areaId}" checked="true">
                                                ${list.id}
                                                    <%if(list.areaId==0){%>
                                                        中国&nbsp;&nbsp;
                                                    <%}else{%>
                                                        ${list.name!}&nbsp;&nbsp;
                                                    <%}%>
                                                <%}%>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <span style="vertical-align: top;">国家： </span>
                                                <select name="country" id="selCountries" onchange="ger_ress('00',this,'selProvinces')" size="10" style="width: 80px;">
                                                    <option value="00">中国</option>
                                                </select>
                                                <span style="vertical-align: top;">省份： </span>
                                                <select name="province" id="selProvinces" onchange="ger_ress('2',this,'selCities')" size="10" style="width: 80px;">
                                                    <option value="">请选择...</option>
                                                </select>
                                                <span style="vertical-align: top;">城市： </span>
                                                <select name="city" id="selCities" onchange="ger_ress('3',this,'selDistricts')" size="10" style="width: 80px;">
                                                    <option value="">请选择...</option>
                                                </select>
                                                <span style="vertical-align: top;">区/县：</span>
                                                <select name="district" id="selDistricts" size="10" style="width: 130px;">
                                                    <option value="">请选择...</option>
                                                </select>

                                                <span style="vertical-align:bottom;"><input value="+" class="button" onclick="addRegion()" type="button"></span>
                                            </td>
                                        </tr>
                                    </table>
                                </fieldset>
                            </td>
                        </div>

                        <div class="form-group">
                                <label class="col-sm-2 control-label">介绍</label>
                                <div class="col-sm-3">
                                    <textarea name="deliveryType.description" rows="8" cols="80" class="form-control light-input">${deliveryType.description!}</textarea>
                                </div>

                            </div>
                        <div class="form-group" style="margin-top: 24px">
                            <label class="col-sm-2 control-label "></label>
                            <div class="col-sm-4 col-sm-offset-0">
                                <button class="hive-btn-cancle" id="btn_cancle" type="button" onclick="history.back()">&nbsp;取消&nbsp;</button>
                                <button class="hive-btn hive-btn-primary margin-left-8" type="submit">&nbsp;提交&nbsp;
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

</div>
<% include("../inc/input_js.html"){}%>
<script type="text/javascript">
    function changeDelivery(){
        var deliveryMethod=$("select[name='deliveryMethod']").val();
        if(deliveryMethod=='selfDelivery'){
            $("#defaultDeliveryCorp").hide();
            $("#firstWeight").hide();
            $("#continueWeight").hide();
            $("#firstWeightPrice").hide();
            $("#continueWeightPrice").hide();
        }else{
            $("#defaultDeliveryCorp").show();
            $("#firstWeight").show();
            $("#continueWeight").show();
            $("#firstWeightPrice").show();
            $("#continueWeightPrice").show();
        }
    }
</script>
<script>
    /**
     * 添加一个区域
     */
    function addRegion() {
        var selCountry  = document.forms['theForm'].elements['country'];
        var selProvince = document.forms['theForm'].elements['province'];
        var selCity     = document.forms['theForm'].elements['city'];
        var selDistrict = document.forms['theForm'].elements['district'];
        var regionCell  = document.getElementById("regionCell");

        if (selDistrict.selectedIndex > 0) {
            regionId = selDistrict.options[selDistrict.selectedIndex].value;
            regionName = selDistrict.options[selDistrict.selectedIndex].text;
        } else {
            if (selCity.selectedIndex > 0) {
                regionId = selCity.options[selCity.selectedIndex].value;
                regionName = selCity.options[selCity.selectedIndex].text;
            } else {
                if (selProvince.selectedIndex > 0) {
                    regionId = selProvince.options[selProvince.selectedIndex].value;
                    regionName = selProvince.options[selProvince.selectedIndex].text;
                } else {
                    if (selCountry.selectedIndex >= 0) {
                        regionId = selCountry.options[selCountry.selectedIndex].value;
                        regionName = selCountry.options[selCountry.selectedIndex].text;
                    } else {
                        return;
                    }
                }
            }
        }

        // 检查该地区是否已经存在
        exists = false;
        console.log(document.forms['theForm'].elements.length);
        for (i = 0; i < document.forms['theForm'].elements.length; i++) {
            if (document.forms['theForm'].elements[i].type=="checkbox") {
                if (document.forms['theForm'].elements[i].value == regionId) {
                    exists = true;
                    layer.msg('选定的地区已经存在。');
                }
            }
        }
        // 创建checkbox
        if (!exists) {
            regionCell.innerHTML += "<input type='checkbox' name='regions[]' value='" + regionId + "' checked='true' /> " + regionName + "&nbsp;&nbsp;";
        }
    }

    function ger_ress(type,obj,seobj){
        parent_id = $(obj).val();
        if(parent_id=="" || typeof(parent_id)=='undefined'){ return false; }
        $.post('getAreaByParent',
            {action:'get_ress',type:type,parent_id:parent_id},
            function(data){
            $('#'+seobj).html(data);
            if(type==1){
                $('#selCities').html('<option value="0">请选择...</option>');
                $('#selDistricts').html('<option value="0">请选择...</option>');
            }else if(type==2){
                $('#selDistricts').html('<option value="0">请选择...</option>');
            }
        });
    }

    function compute_mode(t1,t2){
        $('.'+t1).show();
        $('.'+t2).hide();
    }

</script>
<!--<script type="text/javascript" src="http://sc.35wang.cn/admin/js/order_remind.js"></script>-->

<!--<script language="javascript" type="text/javascript">
    //根据屏幕的高度决定左侧菜单的高度
    changesize();

    function changesize() {
        // 获取窗口高度
        if (window.innerHeight)
            winHeight = window.innerHeight;
        else if ((document.body) && (document.body.clientHeight))
            winHeight = document.body.clientHeight;
        // 通过深入 Document 内部对 body 进行检测，获取窗口大小
        if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
            winHeight = document.documentElement.clientHeight;
        }
    }

    document.getElementById('mainss').style.height = (winHeight - 10) + "px";
</script>-->
</body>
</html>